/*
https://leetcode-cn.com/problems/bitwise-ors-of-subarrays/solution/zi-shu-zu-an-wei-huo-cao-zuo-by-leetcode/
 */
import java.util.HashSet;
import java.util.Set;

public class Solution898 {
    public int subarrayBitwiseORs(int[] arr) {
        Set<Integer> ans=new HashSet<>();
        Set<Integer> cur=new HashSet<>();
        for (int i : arr) {
            Set<Integer> cur2=new HashSet<>();
            cur2.add(i);
            for (Integer integer : cur) {
                cur2.add(i|integer);
            }
            ans.addAll(cur2);
            cur=cur2;
        }
        return ans.size();
    }

    public static void main(String[] args) {
        System.out.println(new Solution898().subarrayBitwiseORs(new int[]{1,2,4}));
    }
}
